package com.zhengshang;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zhengshang.common.constant.app.AppConstant;
import com.zhengshang.common.constant.app.PhoneBillConstants;
import com.zhengshang.common.oss.OssUtils;
import com.zhengshang.common.utils.DateUtils;
import com.zhengshang.common.utils.PromoCodeUtils;
import com.zhengshang.common.utils.uuid.IdUtils;
//import fulu.sup.open.api.core.MethodConst;
//import fulu.sup.open.api.model.InputProductDto;
//import fulu.sup.open.api.sdk.DefaultOpenApiClient;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.StampedLock;

/**
 * @author HY
 * @version 1.0.0
 * @ClassName MyTest.java
 * @Description TODO
 * @createTime 2021年03月02日 15:32
 */
public class MyTest {
    public static void main(String[] args) {
//        //先定义取值范围
//        String chars = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ";
//        Map<String, String> map = new HashMap<>();
//        for (int j = 0; j < 100; j++) {
//            int random = (int) (Math.random() * (chars.length() * chars.length() * chars.length() * chars.length() * chars.length()));
//            String code = to32String(new BigInteger(random + ""));
//            map.put(code, code);
//            System.out.println("生成code：" + code);
//        }

//        for (int j = 0; j < 100000; j++) {
//            StringBuffer value = new StringBuffer();
//            for (int i = 0; i < 5; i++) {
//                value.append(chars.charAt((int)(Math.random() * (chars.length()))));
//            }
//            map.put(value.toString(), value.toString());
//        }

//        System.out.println("生成随机数的数量：" + map.keySet().size());

        //99乘法表
//        m(9);

//        for (int j = 0; j < 100000; j++) {
//            String code = getPromoCode();
//            map.put(code, code);
//        }
//        System.out.println("生成随机数的数量：" + map.keySet().size() + "，重复生成了 " + count + " 个code");

//        for (int i = 0; i < 100; i++) {
//            System.out.println((int)(Math.random() * 900000) + 100000);
//        }

//        Lock lock = new ReentrantLock();
//        StampedLock lock2 = new StampedLock();
//        AtomicInteger count = new AtomicInteger();
//        count.incrementAndGet();
//
//
//        T t = new T();
//        System.out.println(ClassLayout.parseInstance(t).toPrintable());
//
//        synchronized (t) {
//            System.out.println(ClassLayout.parseInstance(t).toPrintable());
//        }
//        System.out.println(ClassLayout.parseInstance(t).toPrintable());

//        String oldKey = "video/dongzuo/2021/05/18/惊奇队长.mp4";
//        System.out.println(OssUtils.copy(oldKey, "video/2021/05/18/" + OssUtils.newFileName(oldKey)));
//        System.out.println(OssUtils.getVideoName(oldKey));

//        String path = DateUtils.datePath();
//        String keyPrefix = "video" + "/dongzuo/" + path + "/";
//        JSONArray jsonArray = OssUtils.listObjectV2(keyPrefix);
//        System.out.println(jsonArray);

//        Calendar now = Calendar.getInstance();
//        int week = now.get(Calendar.DAY_OF_WEEK);
//        System.out.println(now.get(Calendar.HOUR_OF_DAY));
//        System.out.println(now.get(Calendar.MINUTE));
//        System.out.println(now.get(Calendar.SECOND));

//        DefaultOpenApiClient client =  new DefaultOpenApiClient("http://pre.openapi.fulu.com/api/getway", "i4esv1l+76l/7NQCL3QudG90Fq+YgVfFGJAWgT+7qO1Bm9o/adG/1iwO2qXsAXNB", "0a091b3aa4324435aab703142518a8f7", MethodConst.OPEN_API_PHONE_ORDER_ADD);
////        DefaultOpenApiClient client =  new DefaultOpenApiClient("https://openapi.fulu.com/api/getway", PhoneBillConstants.APP_KEY, PhoneBillConstants.APP_SECRET, MethodConst.OPEN_API_PHONE_ORDER_ADD);
////        DefaultOpenApiClient client = new DefaultOpenApiClient("", PhoneBillConstants.APP_KEY, PhoneBillConstants.APP_SECRET, "fulu.goods.list.get");
////        InputProductDto dto = new InputProductDto();
////        dto.setProductId("15751870");
//
////        client.setBizObject(dto);
//        JSONObject bizContent = new JSONObject();
//        bizContent.put("charge_phone", "15972368779");
//        bizContent.put("charge_value", "50");
//        bizContent.put("customer_order_no", IdUtils.getOrdercode(AppConstant.ORDERNUM_PREFIX_BILL));
//        client.setBizContent(bizContent.toJSONString());
//        String result = client.excute();
//        System.out.println(result);

//        String orderNum = IdUtils.getOrdercode(AppConstant.ORDERNUM_PREFIX_BILL);
////        System.out.println(orderNum);
//
//        DefaultOpenApiClient client =  new DefaultOpenApiClient(PhoneBillConstants.GETWAY_HTTP, PhoneBillConstants.APP_KEY, PhoneBillConstants.APP_SECRET, "fulu.goods.template.get");
//        JSONObject bizContent = new JSONObject();
//        bizContent.put("charge_account", "18612393590");
//        bizContent.put("buy_num", 1);
//        bizContent.put("product_id", 12380302);
//        bizContent.put("customer_order_no", orderNum);
//        client.setBizContent(bizContent.toJSONString());
//        JSONObject billResultObj = JSONObject.parseObject(client.excute());
//        System.out.println(billResultObj);
        System.out.println(IdUtils.getOrdercode("PB"));


    }

    private static class T {
    }

    private static Map<String,String> map = new HashMap<>();
    private static int count = 0;

    private static String getPromoCode() {
        String promoCode = PromoCodeUtils.getPromoCode();
        if (map.containsKey(promoCode)) {
            count++;
            return getPromoCode();
        }
        return promoCode;
    }

    public static void m(int i) {
        if (i == 1) {
            System.out.println("1*1=1 ");
        } else {
            m(i - 1);
            for (int j = 1; j <= i; j++) {
                System.out.print(j + "*" + i + "=" + j * i + " ");
            }
            System.out.println();
        }
    }

    private static String chars = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ";
    private static String to32String(BigInteger i) {
        BigDecimal divide = new BigDecimal(32);
        BigDecimal decimal = new BigDecimal(i);
        String res = "";
        while (BigDecimal.ZERO.compareTo(decimal) != 0){
            BigDecimal[] divRes = decimal.divideAndRemainder(divide);
            decimal = divRes[0];
            res =  chars.charAt(divRes[1].intValue()) + res;
        }
        return res;
    }

}
